#!/bin/bash
# ========================================
# ConfigTools - Maven Shade Plugin 打包脚本
# 方案一：单一JAR文件打包
# ========================================

echo ""
echo "========================================"
echo "ConfigTools Maven Shade Plugin 打包"
echo "========================================"
echo ""

# 切换到项目根目录
cd "$(dirname "$0")/.."
if [ ! -f "pom.xml" ]; then
    echo "[错误] 找不到 pom.xml 文件！请确保在正确的项目目录中运行。"
    exit 1
fi

echo "当前目录: $(pwd)"
echo "开始清理和打包..."
mvn clean package -q

if [ $? -ne 0 ]; then
    echo ""
    echo "[错误] 打包失败！请检查Maven配置和依赖。"
    exit 1
fi

echo ""
echo "========================================"
echo "打包成功！"
echo "========================================"
echo ""
echo "JAR文件位置: target/config-tools-1.0.0.jar"

# 获取文件大小
if [ -f "target/config-tools-1.0.0.jar" ]; then
    size=$(stat -c%s "target/config-tools-1.0.0.jar" 2>/dev/null || stat -f%z "target/config-tools-1.0.0.jar" 2>/dev/null)
    sizeMB=$((size / 1024 / 1024))
    echo "文件大小: 约 ${sizeMB} MB"
fi

echo ""
echo "运行方式:"
echo "  java -jar target/config-tools-1.0.0.jar"
echo ""
echo "分发说明:"
echo "  - 只需分发 config-tools-1.0.0.jar 文件"
echo "  - 目标机器需要安装 Java 11+ 运行时"
echo "  - 适合桌面应用分发和简单部署"
echo ""
